var test;
$(document).click(function () {
    layer.close(test)
});

/**
 * 点击再预约
 */
appointment = function (customerId,reservationsId,doctor) {
    var cid = customerId + "," + reservationsId + "," + doctor;
    var index = layer.open({
        type: 2,
        title: '新建预约',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_appointment/' + cid
    });
    this.layerIndex = index;
};

/**
 * 点击进入患者详情
 */
openBilee = function (ide) {
    var index = layer.open({
        type: 2,
        title: '到店客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileLists/' + ide
    });
    this.layerIndex = index;
};

/**
 * 点击修改
 */
modifyAppointment = function(ids) {
    var index = layer.open({
        type: 2,
        title: '修改预约客户',
        area: ['60%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_addTasks/' + ids
    });
    this.layerIndex = index;
};
/**
 * 点击取消预约
 */
cancelAppointment = function(customerId,customerName) {
    if(confirm("确定患者【"+customerName+"】要取消预约?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/cancelAppointment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('取消预约成功!');
                $('#calendar').fullCalendar( 'refetchEvents' );
                parent.layer.close(parent.layer.getFrameIndex(window.name))
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击挂号
 */
registerAppointment = function (customerId,customerName) {
//        var idName=customerId+","+customerName;
//        var index = layer.open({
//            type: 2,
//            title: '输入标识号',
//            area: ['50%', '90%'], //宽高
//            fix: true, //不固定
//            maxmin: true,
//            content: Feng.ctxPath + '/customer/to_regresses/' + idName
//        });
//        this.layerIndex = index;
    if(confirm("确定患者【"+customerName+"】已挂号?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/regresses",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('患者' + customerName + '挂号成功!');
                $('#calendar').fullCalendar( 'refetchEvents' );
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};

sureAppointment = function (customerId,customerName) {
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/sureAppointment",
        type: "post",
        data: {
            customerId: customerId
        },
        success: function (data) {
            // Feng.success('患者' + customerName + '开始治疗!');
            $('#calendar').fullCalendar( 'refetchEvents' );
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};

/**
 * 点击开始治疗
 */
startTreatment = function (customerId,customerName) {
    if(confirm("确定患者【"+customerName+"】已经开始治疗?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/startTreatment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('患者' + customerName + '开始治疗!');
                $('#calendar').fullCalendar( 'refetchEvents' );
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击完成治疗
 */
completionTreatment = function (customerId,customerName) {
    if(confirm("确定患者【"+customerName+"】已经完成治疗?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/completionTreatment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('患者' + customerName + '完成治疗!');
                $('#calendar').fullCalendar( 'refetchEvents' );
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击离开
 */
alreadyLeave = function (customerId,customerName) {
    if(confirm("确定患者【"+customerName+"】已经离开?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/alreadyLeave",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                Feng.success('患者' + customerName + '已经离开!');
                $('#calendar').fullCalendar( 'refetchEvents' );
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击回退
 */
fallbackAction = function (customerId,customerName,arrivalStatus) {
    if(confirm("确定要回退么？ 患者【"+customerName+"】")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/fallbackAction",
            type: "post",
            data: {
                customerId: customerId,
                arrivalStatus:arrivalStatus
            },
            success: function (data) {
                Feng.success('患者' + customerName + '回退成功!');
                $('#calendar').fullCalendar( 'refetchEvents' );
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击打印
 */
printingAppointment = function (customerId) {
    var index = layer.open({
        type: 2,
        title: '打印客户信息',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/printingAppointment/' + customerId
    });
    this.layerIndex = index;
};
/**
 * 点击刷新
 */
btnRefetchEvents = function () {
    $('#calendar').fullCalendar( 'refetchEvents' );
};

